<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" import="java.util.*,java.text.SimpleDateFormat,com.epam.tcs.actions.*,com.epam.tcs.dao.hibernate.entities.*"%>
<%@ include file="../template/header.jsp" %>
<%@ include file="../template/left_menu_alt.jsp" %>
<div id="content">
	<div id="breadcrumbs">
		<c:if test="${requestScope.breadcrumbs != null}">
			<c:set var="i" value="0"/>
			<c:forEach items="${requestScope.breadcrumbs}" var="bc">
				<a href="${pageContext.request.contextPath}${bc.getUrl()}">${bc.getCaption()}</a>		
			</c:forEach>
		</c:if>
	</div>
	<span style="color: green;">
		${requestScope.message}
	</span>
	<c:if test="${sessionScope.listStudents != null}">
	<form name="student_form" method=post action="">
	<table>	
		<tr>
			<th><input type="checkbox" onclick="checkAll()" name="student_check"/></th>
			<th></th>
			<th>Фамилия</th>
			<th>Имя</th>
			<th>Отчество</th>	
			<th>Группа</th>		
			<th>Почта</th>
			<th>Телефон</th>
			<th>Год рождения</th>	
		</tr>
		<c:forEach items="${sessionScope.listStudents}" var="st">
			<tr class="data">
				<td><input type="checkbox" name="student_check_${st.student_id}"/></td>
				<td><a href="${pageContext.request.contextPath}/tcs/student/edit?student_id=${st.student_id}"><span class="ui-icon ui-icon-pencil"></span></a></td>
				<td>${st.lastName}</td>
				<td>${st.firstName}</td>
				<td>${st.middleName}</td>
				<td>${st.group.name}</td>
				<td>${st.email}</td>
				<td>${st.phone}</td>
				<td>${st.birthday}</td>				 	  
			</tr>
		</c:forEach>
		<tr>
			<td colspan="9">
			<c:if test="${requestScope.pageElements != null && requestScope.pageElements.size() > 1}" >
				<div class="paging">
					<c:forEach items="${requestScope.pageElements}" var="page" >
						<div class="page_element" name="page_element_${page.id}">
							<a href="${pageContext.request.contextPath}${page.url}">${page.id}</a>
						</div>
					</c:forEach>
				</div>
			</c:if>
			</td>
		</tr>
	</table>
	</form>
	</c:if>	
</div>
<script type="text/javascript">
$(function() {
	$('#del_student').bind('click', function(){
		deleteStudents();
	});
	$('#add_student').bind('click', function(){
		addStudent();
	});
	
	if (getParameterByName("page") != null && getParameterByName("page") > 1) {
		$("div[name = page_element_" + getParameterByName("page") + "]").addClass("selected");		
	} else {
		$("div[name = page_element_1]").addClass("selected");
	}
});

function getParameterByName(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}
function addStudent() {
	window.location = "${pageContext.request.contextPath}/tcs/student/add";
}
function checkAll() {
	if ($("input[name = student_check]").attr("checked")) {
		$("input[name ^= student_check]").each(
			function() {
				$(this).attr("checked",true);
			}
		);
	} else {
		$("input[name ^= student_check]").each(
				function() {
					$(this).attr("checked",false);
				}
			);
	}
}

function deleteStudents() {
	var students = [];
	$("input[name ^= student_check]:checked").each(
		function(index) {
			students[index] = $(this).attr("name");
		}
	);
	$("form[name = student_form]").attr("action", "${pageContext.request.contextPath}/tcs/student/del");
	$("form[name = student_form]").submit();	
}
</script>
<%@ include file="../template/footer.jsp" %>